#ifndef __CPOMQTT_H__
#define __CPOMQTT_H__

#include <mosquitto.h>

#include <stdbool.h>
#include <string.h>

#define ES_MQTT_HOST		"localhost"
//#define ES_MQTT_HOST		"192.168.37.130"
//#define ES_MQTT_HOST		"172.16.100.59"
#define ES_MQTT_PORT		(1883)
#define ES_MQTT_KEEPALIVE	(60)

/* cmd = addDeivce 报文会发到这个主题，直接订阅这个主题 */
#define MQTT_SUB_INIT_CMD       "local/gateway/gateway/command"

/* 更新虚点 cmd = write 报文应该订阅 /local/gatewaydeviceKey/VirPointdeviceKey/command 
 * 其中 VirPointdeviceKey 是从 addDeivce 报文中提取的，
 * 所以将 MQTT_SUB_VIRPOINT_PRE 和 VirPointdeviceKey/command 组装起来再订阅 
 */

/* 
 * 由于本app也会生成write报文发送到 /local/gatewaydeviceKey/RealPointdeviceKey/command
 * 所以不能简单订阅 /local/gatewaydeviceKey/+/command 来覆盖 write 和 addDeivce
 * 否则会自发自收
 */

#define MQTT_SUB_VIRPOINT_PRE   "local/gateway"

/* 实点位的 value 报文会发到/local/gatewaydeviceKey/<IOdeviceKey>, 直接订阅下面这个主题 */
#define MQTT_SUB_REALPOINT      "local/gateway/+"

/* 当发送某个json报文时, 根据发送内容, 将 MQTT_PUB_PREFIX 和其他字符串组合出一个topic */
#define MQTT_PUB_PREFIX         "local/gateway"

void cpo_mqtt_msg_cb(struct mosquitto *mosq, void *userdata, const struct mosquitto_message *msg);
void cpo_mqtt_log_cb(struct mosquitto *mosq, void *userdata, int level, const char *str);
void cpo_mqtt_conn_cb(struct mosquitto *mosq, void *userdata, int rc);
void cpo_mqtt_sub_cb(struct mosquitto *mosq, void *userdata, int mid, int qos_count, const int *granted_qos);
void cpo_mqtt_pub_cb(struct mosquitto *mosq, void *userdata, int mid);

#endif //__CPOMQTT_H__